import java.io.IOException;
import java.sql.SQLException;
import java.util.Scanner;

public class JDBCtext {

    public static void main(String[] args) throws SQLException, IOException {
        StudentRepo repo = new StudentDatabaseRepo();
        while (true) {
            System.out.println("请选择你想要选择的功能");
            System.out.println("1:录入学生\n" +
                    "2：查询学生\n" +
                    "3：删除学生\n" +
                    "4：修改学生\n" +
                    "5：所有学生\n" +
                    "0：退出");
            Scanner scanner = new Scanner(System.in);

            String one = scanner.nextLine();
            switch (one) {
                case "1": {
                    // 打印提示信息
                    System.out.println("请输入你的学号、班级、姓名、性别和年龄并用空格隔开");
                    // 读取用户的输入
                    String s = scanner.nextLine();
                    // 把用户的输入进行分割
                    String[] ss = s.split(" ");
                    Student student = new Student();
                    student.setStuNum(ss[0]);
                    student.setClassName(ss[1]);
                    student.setName(ss[2]);
                    student.setSex(ss[3]);
                    student.setAge(Integer.valueOf(ss[4]));
                    repo.newStudent(student);
                    break;
                }
                case "2": {
                    // 打印提示信息
                    System.out.println("请输入你要查找的学号或姓名");
                    // 获得用户的输入
                    String stuNumOrName = scanner.nextLine();
                    Student student = repo.findStudent(stuNumOrName);
                    System.out.println(student);
                    break;
                }
                case "3": {
                    // 打印提示信息
                    System.out.println("请输入你要删除的学号");
                    // 获得用户的输入
                    String stuNum1 = scanner.nextLine();
                    repo.deleteStudent(stuNum1);
                    break;
                }
                case "4": {
                    // 打印提示信息
                    System.out.println("请输入你要修改的学号");
                    // 获得用户的输入
                    String stuNum1 = scanner.nextLine();
                    Student student = repo.findStudent(stuNum1);
                    System.out.println(student);
                    // 打印提示信息
                    System.out.println("请输入你的学号、班级、姓名、性别和年龄并用空格隔开");
                    // 读取用户的输入
                    String s = scanner.nextLine();
                    // 把用户的输入进行分割
                    String[] ss = s.split(" ");
                    student.setStuNum(ss[0]);
                    student.setClassName(ss[1]);
                    student.setName(ss[2]);
                    student.setSex(ss[3]);
                    student.setAge(Integer.valueOf(ss[4]));
                    repo.updateStudent(student);
                    break;
                }

                case "0":
                    return;
                default:
                    System.out.println("你输入的不合格，请重新输入");
                    break;
            }
        }

    }
}
